package com.atXiao.滑动窗口;

import com.sun.jmx.remote.internal.ArrayQueue;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Demo2 {


    public static void main(String[] args) {


        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        ArrayDeque<Integer> num = new ArrayDeque<>();
        ArrayDeque<Character> fuhao = new ArrayDeque<>();
        String str = "";
        for (int i = 0; i < s.length(); i++) {
            if (Character.isDigit(s.charAt(i))) {
                str += s.charAt(i);
                if (i == s.length() - 1) {
                    int n = Integer.valueOf(str);
                    char f = fuhao.peek();
                    if (f == '$') {
                        num.push(n);
                    } else {
                        int m = num.pop();
                        fuhao.pop();
                        num.push(jinghao(m, n));
                    }
                }
            } else {
                if (fuhao.isEmpty()) {
                    num.push(Integer.valueOf(str));
                    str = "";
                    fuhao.push(s.charAt(i));
                } else {
                    int n = Integer.valueOf(str);
                    char f = fuhao.peek();
                    str = "";
                    if (f == '$') {
                        num.push(n);
                    } else {
                        int m = num.pop();
                        fuhao.pop();
                        num.push(jinghao(m, n));
                    }
                    fuhao.push(s.charAt(i));
                }
            }

        }
        int n = num.size();
        while (n > 1) {
            num.addLast(daole(num.pollLast(), num.pollLast()));
            n--;
        }
        System.out.println(num.peek());

    }

    public static int jinghao(int x, int y) {
        return 4 * x + 3 * y + 2;
    }

    public static int daole(int x, int y) {
        return 2 * x + y + 3;
    }

}


